<?php

namespace app\api\controller;

use app\common\model;

// 任务控制器
class TaskAssignment extends TaskBase
{
    protected $noNeedLogin = ['taskList'];

    /**
     * 任务列表
     */
    public function taskList () {
        $page = $this->request->param('page', 1);
        $pageSize = $this->request->param('pageSize', 15);

        $now = time();

        $list = model\Assignment::where('start_time','<=', $now)
            ->where('end_time','>', $now)
            ->order('start_time desc')
            ->page($page, $pageSize)
            ->select();
        if($list){
            foreach ($list as &$assignment) {
                $label_ids = $assignment['label_ids'];
                $assignment['label_text'] = [];
                if (!empty($label_ids)) {
                    $label = model\Label::whereIn('id', $assignment['label_ids'])->where('status',1)->column('name');
                    $assignment['label_text'] = $label ? $label:[];
                }
                // $assignment['video_url'] ="https://aisaas.mynatapp.cc" .$assignment['videofile'];
            }
        }
        return json(["code" =>200, "msg" =>"获取成功", "data" => $list]);
    }
}